package controller

import (
	"net/http"

	"github.com/gin-gonic/gin"

	"sdn-executor/utils/erros"
)

// Response 响应消息结构体.
type Response struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
	Data any    `json:"data"`
}

// SendResponse 发送响应内容.
func SendResponse(c *gin.Context, err error, data any) {
	code, msg := erros.DecodeCodeMsg(err)

	c.JSON(http.StatusOK, Response{
		Code: code,
		Msg:  msg,
		Data: data,
	})
}
